#!/usr/bin/python3
# -*- coding: utf-8 -*-
import pandas as pd
import numpy  as np

eps = 1e-8

def signal(*args):
    # ZhenFu
    df = args[0]
    n = args[1]
    factor_name = args[2]

    high = df['high'].rolling(n, min_periods=1).max()
    low = df['low'].rolling(n, min_periods=1).min()
    df[factor_name] = high / (low + eps) - 1

    return df
